//
//  ASPracticeUnitInfoVC.m
//  AttendenceSys
//
//  Created by 窦芳俊 on 2017/4/1.
//  Copyright © 2017年 窦芳俊. All rights reserved.
//

#import "ASPracticeUnitInfoVC.h"
#import "ASInfoCell.h"

@interface ASPracticeUnitInfoVC () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView  *infoTableView;
@property (nonatomic, strong) NSArray      *infoArray;
@property (nonatomic, strong) UIButton     *logoutBtn;

@end

@implementation ASPracticeUnitInfoVC

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _infoArray = @[@"账户编号",@"账户名称",@"单位性质",@"账户地址"];
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self initView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)initView
{
    UIImageView* bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0,
                                                                        0,
                                                                        self.view.frame.size.width,
                                                                        self.view.frame.size.height)];
    bgView.backgroundColor = [UIColor whiteColor];
    //bgView.image = [UIImage imageNamed:@"bg_personal"];
    bgView.userInteractionEnabled = YES;
    [self.view addSubview:bgView];
    
    _infoTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _infoTableView.frame = CGRectMake(0, 0, self.view.frame.size.width, 250);
    _infoTableView.delegate = self;
    _infoTableView.dataSource = self;
    _infoTableView.backgroundColor = [UIColor whiteColor];
    _infoTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_infoTableView registerClass:[ASInfoCell class] forCellReuseIdentifier:NSStringFromClass([ASInfoCell class])];
    [bgView addSubview:_infoTableView];
    
    // 退出登录
    _logoutBtn = [[UIButton alloc] initWithFrame:CGRectMake(55,
                                                            _infoTableView.frame.origin.y + _infoTableView.frame.size.height + 68,
                                                            self.view.frame.size.width - 2 * 55,
                                                            50)];
    [_logoutBtn setTitle:@"退出登录" forState:UIControlStateNormal];
    [_logoutBtn addTarget:self action:@selector(logout) forControlEvents:UIControlEventTouchUpInside];
    [_logoutBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _logoutBtn.backgroundColor = RGB(253, 119, 62);
    [bgView addSubview:_logoutBtn];
}

- (void)logout
{
    ASAppDelegate *appDelegate = [ASAppDelegate sharedAppDelegate];
    [appDelegate enterLoginView];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_infoArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ASInfoCell class])];
    
    ASInfoCell *infoCell = (ASInfoCell *)cell;
    [infoCell updatePracticeUnitCellStatus:[_infoArray objectAtIndex:[indexPath row]]];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50.0f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end



